<template>
	<view>
		<view class="content-box" >
			<view class="content-section">
				<video id="myVideo" :src="vidioInfo.url" @error="videoErrorCallback" :danmu-list="danmuList"
					enable-danmu danmu-btn controls></video>

				<view class="list-box">
					<view class="items">
						<text>详情</text>
						<view class="danmu-input">
							<input @blur="bindInputBlur" class="input" type="text" placeholder="在此处输入弹幕内容" />
							<view class="send-danmu" @tap="bindSendDanmu">发送</view>
						</view>
					</view>
				</view>
				<!-- <view class="btn-area">
					<button @tap="bindSendDanmu" class="page-body-button" formType="submit">发送弹幕</button>
				</view> -->
				<view class="detail-content-box">
					<view class="vidio-info">
						<view class="vidio-name">{{vidioInfo.name}}</view>
						<view class="playCount-date">
							<text>{{vidioInfo.playCount}}次播放</text>
							<text>{{vidioInfo.pulishTime}}</text>
						</view>
						<view class="desc">{{vidioInfo.desc}}</view>
					</view>
					<view class="recommend-vidio">
						<view class="title">推荐视频</view>
						<view class="vidio-item" v-for="(recommendVidioItem,index) in vidioInfo.recommend" @click="getVidioInfo(recommendVidioItem.id)">

							<view class="cover">
								<image :src="recommendVidioItem.cover">
								</image>
								<view class="playCount">
									<image src="../../static/images/vidioListImg/playcount.png"></image>
									<view>{{recommendVidioItem.playCount}}</view>
								</view>

							</view>

							<view class="content">
								<text>{{recommendVidioItem.name}}</text>
								<text>{{recommendVidioItem.playCount}}次播放</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'video',
				src: '',
				inputValue: '',
				// 视频信息
				vidioInfo: {},
				danmuList: [{
						text: '第 1s 出现的弹幕',
						color: '#ff0000',
						time: 1
					},
					{
						text: '第 3s 出现的弹幕',
						color: '#ff00ff',
						time: 3
					}
				]
			};
		},
		onLoad(id) {
			this.getVidioInfo(id.id)
		},
		onReady: function(res) {
			this.videoContext = uni.createVideoContext('myVideo')
		},
		methods: {
			// 获取视频信息
			getVidioInfo(id) {
				console.log(id)
				uni.request({
					url: 'http://music.jsososo.com/apiMix/mv',
					data: {
						id: id,
						_p: 'qq',
						_t: 1623320547749
					},
					success: (res) => {
						this.vidioInfo = res.data.data
						console.log(res)
					}
				})
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 100,
					
				});
			},
			bindInputBlur: function(e) {
				this.inputValue = e.target.value
			},
			bindButtonTap: function() {
				var that = this
				uni.chooseVideo({
					sourceType: ['album', 'camera'],
					maxDuration: 60,
					camera: ['front', 'back'],
					success: function(res) {
						this.src = res.tempFilePath
					}
				})
			},
			bindSendDanmu: function() {
				this.videoContext.sendDanmu({
					text: this.inputValue,
					color: this.getRandomColor()
				})
			},
			videoErrorCallback: function(e) {
				console.log('视频错误信息:')
				console.log(e.target.errMsg)
			},
			getRandomColor: function() {
				const rgb = []
				for (let i = 0; i < 3; ++i) {
					let color = Math.floor(Math.random() * 256).toString(16)
					color = color.length == 1 ? '0' + color : color
					rgb.push(color)
				}
				return '#' + rgb.join('')
			},
			
		}
	}
</script>

<style lang="scss">
	.content-box {
		.content-section {

			#myVideo {
				width: 750rpx;
				height: 400rpx;
			}
		}

		.list-box {
			width: 750rpx;
			margin-top: -10rpx;
			font-size: $uni-font-size-base;

			.items {
				height: 80rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-left: 40rpx;
				border-top: solid 1px #EBECEE;
				border-bottom: solid 1px #EBECEE;

				.danmu-input {
					display: flex;
					margin-right: 20rpx;

					.input {
						border-bottom: solid 1px skyblue;
					}

					.send-danmu {
						width: 100rpx;
						height: 56rpx;
						background-color: skyblue;
						font-size: $uni-font-size-base;
						text-align: center;
						line-height: 56rpx;
						border-radius: 5rpx;
						color: white;
						

					}
					.send-danmu:active{
						background-color: #70B2CD;
					}
				}
			}
		}

		.detail-content-box {
			width: 750rpx;
			min-height: 750rpx;
			background-color: #F9F9F9;
			font-size: $uni-font-size-base;

			.vidio-info {
				padding: 20rpx 40rpx;
				margin-bottom: 10rpx;
				border-bottom: solid 1px #EDEAEA;

				.vidio-name {
					margin-bottom: 10rpx;
					font-size: $uni-font-size-base + 3rpx;
					font-weight: bold;
				}

				.playCount-date {
					color: gray;
					margin-bottom: 10rpx;

					text:nth-child(1) {
						margin-right: 20rpx;
					}
				}

				.desc {
					color: gray;
				}
			}

			.recommend-vidio {
				width: 730rpx;
				margin: 0 auto;

				.title {
					font-size: $uni-font-size-base + 2rpx;
					font-weight: bold;
					padding-bottom: 10rpx;
					padding-left: 10rpx;
				}

				.vidio-item {
					display: flex;
					margin:0 20rpx 20rpx 20rpx;
					.cover {
						color: white;
						font-size: $uni-font-size-base - 2rpx;
						image {
							width: 230rpx;
							height: 150rpx;
							border-radius: 10rpx;
							margin-right: 20rpx;
						}

						.playCount {
							display: flex;
							margin-top: -50rpx;
							margin-left: 10rpx;
							align-items: center;
							image {
								width: 33rpx;
								height: 33rpx;
							}

						}
					}

					.content {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						height: 100rpx;
						padding-top: 24rpx;

						text:nth-child(1) {
							height: 75rpx;
							font-weight: bold;
							word-break: break-all;
							display: -webkit-box;
							-webkit-box-orient:vertical;
							-webkit-line-clamp:2;
						}

						text:nth-child(2) {
							color: gray;
						}
					}
				}
			}
		}
	}
</style>
